import * as echarts from 'echarts'

export const ChartMixin = {
  props: {
    chartId: { type: String, required: true }
  },
  mounted() {
    this.initChart()
    window.addEventListener('resize', this.onResize)
  },
  beforeDestroy() {
    window.removeEventListener('resize', this.onResize)
  },
  methods: {
    initChart() {
      const chartDom = document.getElementById(this.chartId)
      this.myChart = echarts.init(chartDom)
      this.myChart.setOption(this.option)
    },
    resetChart() {
      this.myChart.setOption(this.option)
    },
    onResize() {
      this.myChart.resize()
    }
  }
}
